package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SystemNotice;
import cn.wolfcode.trip.base.mapper.SystemNoticeMapper;
import cn.wolfcode.trip.base.query.SystemNoticeQuery;
import cn.wolfcode.trip.base.service.ISystemNoticeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SystemNoticeService implements ISystemNoticeService{
    @Autowired
    private SystemNoticeMapper systemNoticeMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        systemNoticeMapper.deleteByPrimaryKey(id);
        return 0;
    }

    @Override
    public SystemNotice selectByPrimaryKey(Long id) {
        return null;
    }

    @Override
    public List<SystemNotice> selectAll() {
        return null;
    }
    //页面的分页方法
    @Override
    public PageInfo<SystemNotice> queryForList(SystemNoticeQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<SystemNotice> list = systemNoticeMapper.selectForList(qo);
        return new PageInfo<>(list);
    }
    //新增或者修改,用于发送通知按钮
    @Override
    public void saveOrUpdate(SystemNotice systemNotice) {
        systemNotice.setCreateTime(new Date());
        systemNotice.setIsnew(1);
        systemNoticeMapper.insert(systemNotice);
    }

    @Override
    public PageInfo queryForPage(SystemNoticeQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<SystemNotice> list = systemNoticeMapper.selectForPage(qo);
        return new PageInfo(list);
    }

    @Override
    public void updateNoticeState(int isnew,Long userId) {
        systemNoticeMapper.updateStateByUserId(isnew,userId);
    }
}